package com.mao.crowd.controller;

import com.mao.crowd.entity.vo.DetailProjectVO;
import com.mao.crowd.entity.vo.OrderProjectVO;
import com.mao.crowd.entity.vo.PortalTypeVO;
import com.mao.crowd.entity.vo.ProjectVO;
import com.mao.crowd.service.api.ProjectService;
import com.mao.crowd.util.ResultEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.util.List;

/**
 * @author maomeng
 * @create 2021-06-23- 13:34
 */
@RestController
public class ProjectProviderContorller {

    @Autowired
    private ProjectService projectService;


    @RequestMapping("/get/project/detail/remote/{projecrId}")
    public ResultEntity<DetailProjectVO>  getDetailProjectVORemote(@PathVariable("projecrId") Integer projecrId){
        DetailProjectVO detailProjectVO = null;
        try {
            detailProjectVO = projectService.getDetailProjectVO(projecrId);
            return ResultEntity.successWithData(detailProjectVO);
        } catch (ParseException e) {
            e.printStackTrace();
            return ResultEntity.failed(e.getMessage());
        }
    }


    @RequestMapping("/get/portal/type/project/data/remote")
    public ResultEntity<List<PortalTypeVO>> getPortalTypeProjectDataRemote(){
        try {
            List<PortalTypeVO> portalTypeVOList = projectService.getPortalTypeVO();
            return ResultEntity.successWithData(portalTypeVOList);
        } catch (Exception e){
            e.printStackTrace();
            return ResultEntity.failed(e.getMessage());
        }
    }

    @RequestMapping("/save/project/vo/remote")
    public ResultEntity<String> saveProjectVORemote(@RequestBody ProjectVO projectVO, @RequestParam("memberId") Integer memberId){

        try {
            projectService.saveProject(projectVO,memberId);

            return ResultEntity.successWithOutData();

        }catch (Exception e){
            e.printStackTrace();
            return ResultEntity.failed(e.getMessage());
        }
    }
}
